package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Member;
import com.itheima.health.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Map;

public interface OrderMapper extends BaseMapper<Order> {
    @Select("select id,PHONENUMBER from t_member where PHONENUMBER=#{telephone}")
    Member findMemberByOrderDate(@Param("telephone") String telephone);

    @Select("select count(1) from t_order where SETMEAL_ID = #{sid}   MEMBER_ID = #{mid} and ORDERDATE= #{orderDate}")
    int findOrderBySetmeatIdAndMemberIdAndOrderDate(@Param("sid") Integer sid, @Param("mid") Integer id, @Param("orderDate") String orderDate);


    @Select("select tm.`NAME`  as member ,ts.`NAME` as setmeal ,tor.ORDERDATE as orderDate ,tor.ORDERTYPE as orderType " +
            "from t_order tor ,t_member tm ,t_setmeal ts  " +
            "where tor.MEMBER_ID = tm.id and tor.SETMEAL_ID = ts.id " +
            "and tor.ID = #{id}")
    Map findOrderDetailByOrderId(@Param("id") int id);
}
